package com.cong.project.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.cong.project.common.BaseResponse;
import com.cong.project.common.ErrorCode;
import com.cong.project.common.ResultUtils;
import com.cong.project.exception.BusinessException;
import com.cong.project.model.request.ProductAddRequest;
import com.cong.project.model.request.ProductSearchRequest;
import com.cong.project.model.request.TokenUserRequest;
import com.cong.project.model.vo.ClassifyVo;
import com.cong.project.model.vo.MerChantVo;
import com.cong.project.model.vo.ProductDetailVo;
import com.cong.project.model.vo.ProductVo;
import com.cong.project.service.ClassifyService;
import com.cong.project.service.ProductService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 租赁商品
 * @author lhc
 * @date 2022-09-22 10:39
 */
@RestController
@RequestMapping("product")
public class ProductController {

    @Resource
    private ProductService productService;


    /**
     * 查询商品列表
     * @param productSearchRequest
     * @return
     */
    @GetMapping("/list")
    public BaseResponse getProductList(  ProductSearchRequest productSearchRequest,TokenUserRequest tokenUserRequest){
        if (productSearchRequest==null){
            throw new BusinessException(ErrorCode.PARAMS_ERROR);
        }

        IPage<ProductVo> page =  productService.getProductList(productSearchRequest,tokenUserRequest);

        return ResultUtils.success(page);
    }
    /**
     * 查询商品详情
     * @param productSearchRequest
     * @return
     */
    @GetMapping("/detail")
    public BaseResponse getProductDetail(Long productId,TokenUserRequest tokenUserRequest){
        if (productId==null){
            throw new BusinessException(ErrorCode.PARAMS_ERROR);
        }

        ProductDetailVo productDetail =  productService.getProductDetail(productId,tokenUserRequest);

        return ResultUtils.success(productDetail);
    }

    

    /**
     * 添加商品表
     * @param productAddRequest
     * @param tokenUserRequest
     * @return
     */
    @PostMapping("/add")
    public BaseResponse addProduct(@RequestBody ProductAddRequest  productAddRequest,TokenUserRequest tokenUserRequest){
        if (productAddRequest==null){
            throw new BusinessException(ErrorCode.PARAMS_ERROR);
        }
        boolean result = productService.addProduct(productAddRequest,tokenUserRequest);
        return ResultUtils.success(result);
    }



}
